<?php
// 开启错误显示
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

try {
    // 连接到 SQLite 数据库
    $dbPath = __DIR__ . '/buttons.db';
    $db = new PDO('sqlite:' . $dbPath);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // 查询按钮数据
    $stmt = $db->query('SELECT name, url FROM buttons');
    $buttons = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $error = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>AI仓库</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            height: 100vh;
        }
        #menu {
            background-color: #f0f0f0;
            padding: 10px;
            display: flex;
            align-items: center;
        }
        #menu h1 {
            margin: 0;
            margin-right: 20px;
            font-size: 24px;
        }
        #content {
            flex: 1;
            border: none;
        }
        a {
            display: inline-block;
            padding: 10px 20px;
            margin: 5px;
            background-color: #007BFF;
            color: white;
            text-decoration: none;
            border-radius: 5px;
        }
        a:hover {
            background-color: #17314d;
        }
        /* 让靠右按钮显示 */
        #login-button {
            margin-left: auto;
        }
    </style>
</head>
<body>
    <div id="menu">
        <h1>AI仓库</h1>
        <?php if (isset($error)): ?>
            <p style="color: red;"><?php echo $error; ?></p>
        <?php else: ?>
            <?php foreach ($buttons as $button): ?>
                <!-- 动态生成按钮 -->
                <a href="<?php echo htmlspecialchars($button['url']); ?>" target="content">
                    <?php echo htmlspecialchars($button['name']); ?>
                </a>
            <?php endforeach; ?>
        <?php endif; ?>
        <!-- 登录按钮 -->
        <a id="login-button" href="https://sq.00015.cn/">网址仓库</a>
    </div>
    <iframe id="content" name="content" src="https://sq.00015.cn/"></iframe>
</body>
</html>